#include <stdio.h>

#include "mediaparser.h"

void usage(const char *exec)
{
    printf("Usage: %s mediafile\n", exec);
}

void formatDuration(const int duration, int *hour, int *min, int *sec)
{
   *sec = duration % 60;
   *min = duration / 60;
   *hour = *min / 60;
   *min  = *min % 60;   
}

int main(int argc, char **argv)
{
    const char * filename     = NULL;
    MParser::mediaparser * mp = NULL;

    if (argc < 2) {
        usage(argv[0]);
        exit(1);
    }

    filename = argv[1];

    mp = new MParser::mediaparser(filename);

    if (!mp) {
        fprintf(stderr, "failed to init media parser\n");
        exit(1);
    }

    if (mp->open() == 0) {
       mp->parse();
       
       printf("\tFormat:%s\n", mp->getFormat());
       
       int hour, min, sec;
       formatDuration(mp->getDuration(), &hour, &min, &sec);
       printf("\tDuration:%d:%d:%d \n", hour, min, sec);

       mp->getStreamsInfo();

       mp->close();
    }

    delete mp;

    return 0;
}

